#include "../inc/Animal_pri.h"
#include "../../ooc/inc/class_portion.c"


//Class_Portion My Class Full Name
#define _Animal     CP_MC_FNAME




static muc8* toString(_Animal* cthis);
static void setName(_Animal* cthis, const char* name);
static void setAge(_Animal* cthis, int age);



_Animal* OOC_ONAME(OOC_CTOR_NAME(_Animal), a)(const char* name, int age) {

    _Animal* cthis = OOC_CTOR_NAME(_Animal)();

    if (MNULL == cthis)
        return MNULL;

    cthis->setName(cthis, name);
    cthis->setAge(cthis, age);

    return cthis;
}


static _Animal* CPortion_default_init(_Animal* cthis){
    assert(MNULL != cthis);
    OOC_PUB_BLOCK_TNAME(_Animal)* pPubBlock = OOC_GET_PUB_BLOCK(cthis, CP_MC_PKG, CP_MC_TYPE);
    OOC_CLASS_PRO_TNAME(_Animal)* pProtected = (OOC_CLASS_PRO_TNAME(_Animal)*)pPubBlock->tLink.pProtected;
    
    cthis->setName = setName;
    cthis->setAge = setAge;

    cthis->eat = MNULL;
    cthis->breathe = MNULL;

    pProtected->finalize = finalize;
 
    cthis->setName(cthis, "_Animal");
    cthis->setAge(cthis, 0);    
    
    cthis->toString = toString;
    
    return cthis;
}
//======================================================================

static void Cportion_finalize(_Animal* cthis){
    //void
}
//.......................................................................
/* 设置动物的昵称 */
static void setName(_Animal* cthis, const char* name) {
    // 这里假定name小于128个字符，为简化示例代码，不做保护（产品代码中不要这样写）
    strcpy(cthis->name, name);
}

/* 设置动物的年龄 */
static void setAge(_Animal* cthis, int age) {
    cthis->age = age;
}

static muc8* toString(_Animal* cthis){
    static mu8 aString[OBJECT_TO_STRING_MAX];
    
    assert(MNULL != cthis);
    
    snprintf(aString, OBJECT_TO_STRING_MAX, 
            "name:%s age:%d",
            cthis->name,
            cthis->age);
    
    return aString;
}